﻿using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TCDL.GLOBAL;
using TCDL.BUS;

namespace TCDL
{
    public partial class frmQLyLenLich : Form
    {
        XemDSBUS ds = new XemDSBUS();
        int iCount = 1;
        public frmQLyLenLich()
        {
            InitializeComponent();
            cbxTau.DataSource = ds.XemDS("sp_XemDSTau", null, 0);
            cbxTau.DisplayMember = "TenTau";
            cbxTau.ValueMember = "MaTau";

            cbxLichTrinh.DataSource = ds.XemDS("sp_XemDSLichTrinh", null, 0);
            cbxLichTrinh.DisplayMember = "TenLT";
            cbxLichTrinh.ValueMember = "MaLT";        
        }

        private void frmLenLich_Load(object sender, EventArgs e)
        {
            dgvLichVanChuyen.DataSource = ds.XemDS("sp_XemDSVanChuyen", null, 0);
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {

        }

        private void btnThemLenLich_Click(object sender, EventArgs e)
        {
            
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            int iMaLL = Int32.Parse(dgvLichVanChuyen.Rows[SelectedRowIndex].Cells["MaLL"].Value.ToString());
            int iMaTau = Int32.Parse(cbxTau.SelectedValue.ToString());
            
            iCount = 2;
            gConnect[] gCon = new gConnect[iCount];
            gCon[0] = new gConnect("@MaLL", iMaLL);
            gCon[1] = new gConnect("@MaTau", iMaTau);
            ds.ThemDS("Sp_CapNhatTauLenLich", gCon, iCount);
            frmLenLich_Load(sender, e);        
        }

        private void txtDonGia_TextChanged(object sender, EventArgs e)
        {

        }

        int SelectedRowIndex = -1;
        private void dgvLichVanChuyen_SelectionChanged(object sender, EventArgs e)
        {
            if (dgvLichVanChuyen.SelectedCells.Count > 0)
            {
                SelectedRowIndex = dgvLichVanChuyen.SelectedCells[0].RowIndex;
            }

            string strNgayDi = dgvLichVanChuyen.Rows[SelectedRowIndex].Cells["NgayDi"].Value.ToString();
            string strNgayDen = dgvLichVanChuyen.Rows[SelectedRowIndex].Cells["NgayDen"].Value.ToString();
            string strConTrong = dgvLichVanChuyen.Rows[SelectedRowIndex].Cells["SoContainerCon"].Value.ToString();
            int iTau = Int32.Parse(dgvLichVanChuyen.Rows[SelectedRowIndex].Cells["MaTau"].Value.ToString());
            int iTX = Int32.Parse(dgvLichVanChuyen.Rows[SelectedRowIndex].Cells["TaiXeDK"].Value.ToString());
            
            dtpNgayDi.Text = strNgayDi;            
            dtpNgayDen.Text = strNgayDen;            
            txtConTrong.Text = strConTrong;
            cbxTau.SelectedValue = iTau;
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            int iMaLL = Int32.Parse(dgvLichVanChuyen.Rows[SelectedRowIndex].Cells["MaLL"].Value.ToString());

            iCount = 1;
            gConnect[] gCon = new gConnect[iCount];
            gCon[0] = new gConnect("@MaLL", iMaLL);
            ds.ThemDS("Sp_XoaLenLich", gCon, iCount);
            frmLenLich_Load(sender, e);
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            int iMaTau = Int32.Parse(cbxTau.SelectedValue.ToString());
            int iMaLT = Int32.Parse(cbxLichTrinh.SelectedValue.ToString());
            String strNgayDi = dtpNgayDi.Text.Trim();
            DateTime dtbNgayDi = DateTime.Parse(strNgayDi);
            
            iCount = 3;
            gConnect[] gCon = new gConnect[iCount];
            gCon[0] = new gConnect("@ngaydi", dtbNgayDi);
            gCon[1] = new gConnect("@MaTau", iMaTau);
            gCon[2] = new gConnect("@MaLT", iMaLT);
            ds.ThemDS("Sp_ThemLenLich", gCon, iCount);
            frmLenLich_Load(sender, e);
        }
    }
}